﻿/**
 * File:   battery_widget.h
 * Author: 
 * Brief:  
 *
 * Copyright (c) 2024 - 2024 
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * License file for more details.
 *
 */

/**
 * History:
 * ================================================================
 * 2024-10-15  created
 *
 */


#ifndef TK_BATTERY_WIDGET_H
#define TK_BATTERY_WIDGET_H

#include "base/widget.h"

BEGIN_C_DECLS
/**
 * @class battery_widget_t
 * @parent widget_t
 * @annotation ["scriptable","design","widget"]
 * 
 * 在xml中使用"battery\_widget"标签创建控件。如：
 *
 * ```xml
 * <!-- ui -->
 *   <battery_widget name="battery_widget" w="50" h="21" battery_percent="50" style:normal:border_color="#A5A5A5" disg:custom="container" style:normal:bg_color="#92D050" style:normal:border_width="2" style:normal:round_radius="3"/>
 * ```
 *
 * 可用通过style来设置控件的显示风格，如字体的大小和颜色等等。如：
 * 
 * ```xml
 * <!-- style -->
 * <battery_widget>
 *   <style name="default" font_size="32">
 *     <normal text_color="black" />
 *   </style>
 * </battery_widget>
 * ```
 */
typedef struct _battery_widget_t {
  widget_t widget;
  /**
   * @property {int} battery_percent
   * @annotation ["set_prop","get_prop","readable","persitent","design","scriptable"]
   * 电池百分比
   */
  int battery_percent;
  /**
   * @property {bool_t} cap_heading_left
   * @annotation ["set_prop","get_prop","readable","persitent","design","scriptable"]
   * 电池头是否在左部。
   */
  bool_t cap_heading_left;

  /**
   * @property {bool_t} is_charging
   * @annotation ["set_prop","get_prop","readable","persitent","design","scriptable"]
   * 电池是否正在充电。
   * 
   */
  bool_t is_charging;

} battery_widget_t;

#define WIDGET_PROP_BATTERY_PERCENT "battery_percent"
#define WIDGET_PROP_CAP_HEADING_LEFT "cap_heading_left"
#define WIDGET_PROP_IS_CHARGING "is_charging"

/**
 * @method battery_widget_create
 * @annotation ["constructor", "scriptable"]
 * 创建battery_widget对象
 * @param {widget_t*} parent 父控件
 * @param {xy_t} x x坐标
 * @param {xy_t} y y坐标
 * @param {wh_t} w 宽度
 * @param {wh_t} h 高度
 *
 * @return {widget_t*} battery_widget对象。
 */
widget_t* battery_widget_create(widget_t* parent, xy_t x, xy_t y, wh_t w, wh_t h);

/**
 * @method battery_widget_cast
 * 转换为battery_widget对象(供脚本语言使用)。
 * @annotation ["cast", "scriptable"]
 * @param {widget_t*} widget battery_widget对象。
 *
 * @return {widget_t*} battery_widget对象。
 */
widget_t* battery_widget_cast(widget_t* widget);





#define WIDGET_TYPE_BATTERY_WIDGET "battery_widget"

#define BATTERY_WIDGET(widget) ((battery_widget_t*)(battery_widget_cast(WIDGET(widget))))

/*public for subclass and runtime type check*/
TK_EXTERN_VTABLE(battery_widget);

END_C_DECLS

#endif /*TK_BATTERY_WIDGET_H*/
